package com.jumi.microservice.service.jd.service;

import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.domain.kplunion.CategoryService.request.get.CategoryReq;
import com.jd.open.api.sdk.domain.kplunion.CategoryService.response.get.CategoryResp;
import com.jd.open.api.sdk.domain.kplunion.GoodsService.request.query.BigFieldGoodsReq;
import com.jd.open.api.sdk.domain.kplunion.GoodsService.request.query.GoodsReq;
import com.jd.open.api.sdk.domain.kplunion.GoodsService.request.query.JFGoodsReq;
import com.jd.open.api.sdk.domain.kplunion.GoodsService.response.query.*;
import com.jd.open.api.sdk.domain.kplunion.promotionbysubunioni.PromotionService.request.get.PromotionCodeReq;
import com.jd.open.api.sdk.request.kplunion.*;
import com.jd.open.api.sdk.response.kplunion.*;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.config.JdConfig;
import com.jumi.microservice.dto.jd.category.JdCategoryRequest;
import com.jumi.microservice.dto.jd.category.JdCategoryResponse;
import com.jumi.microservice.dto.jd.details.*;
import com.jumi.microservice.dto.jd.keywordquery.JdKeywordQueryRequest;
import com.jumi.microservice.dto.jd.promote.JdPromoteRequest;
import com.jumi.microservice.dto.jd.promote.JdPromoteResponse;
import com.jumi.microservice.dto.jd.query.*;
import com.jumi.microservice.service.JdService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static java.util.Arrays.asList;

@Service
public class JdServiceImpl implements JdService {
    private static final Logger logs = LoggerFactory.getLogger(JdServiceImpl.class);
    @Resource
    JdConfig jdConfig;

    @Override
    @Cacheable(value = "JingDong:query()", key = "#reqRequest.eliteId")
    public TableDataInfo<JdQueryListResponse> query(JFGoodsReqRequest reqRequest) throws Exception {
        logs.info("发起请求");
        TableDataInfo<JdQueryListResponse> tableDataInfo = new TableDataInfo<>();
        JdClient client = new DefaultJdClient("https://api.jd.com/routerjson", "", "c02c79ce1d4aee0500f6c4c7766700fc", "7d361f4207934d438fe775a854c30e3a");
        UnionOpenGoodsJingfenQueryRequest request = new UnionOpenGoodsJingfenQueryRequest();
        JFGoodsReq goodsReq = new JFGoodsReq();
        BeanUtils.copyProperties(reqRequest, goodsReq);
        request.setGoodsReq(goodsReq);
        UnionOpenGoodsJingfenQueryResponse response = client.execute(request);
        List<JFGoodsResp> jfGoodsReqs = new ArrayList<>(asList(response.getQueryResult().getData()));
        List<JdQueryListResponse> jdQueryListResponses = new ArrayList<>();
        for (JFGoodsResp jfGoodsReq : jfGoodsReqs) {
            JdQueryListResponse jdQueryListResponse = new JdQueryListResponse();
            BeanUtils.copyProperties(jfGoodsReq, jdQueryListResponse);
            //类目信息
            JdCategoryInfo jdCategoryInfo = new JdCategoryInfo();
            BeanUtils.copyProperties(jfGoodsReq.getCategoryInfo(), jdCategoryInfo);
            jdQueryListResponse.setCategoryInfo(jdCategoryInfo);
            //佣金信息
            JdCommissionInfo jdCommissionInfo = new JdCommissionInfo();
            BeanUtils.copyProperties(jfGoodsReq.getCommissionInfo(), jdCommissionInfo);
            jdQueryListResponse.setCommissionInfo(jdCommissionInfo);
            //优惠卷信息
            List<JdCoupon> jdCoupons = new ArrayList<>();
            BeanUtils.copyProperties(jfGoodsReq.getCouponInfo().getCouponList(), jdCoupons);
            List<Coupon> coupons = asList(jfGoodsReq.getCouponInfo().getCouponList());
            coupons.forEach(
                    coupon -> {
                        JdCoupon jdCoupon = new JdCoupon();
                        BeanUtils.copyProperties(coupon, jdCoupon);
                        jdCoupons.add(jdCoupon);
                    }
            );
            jdQueryListResponse.setCouponInfo(jdCoupons);
            //图片合集
            List<UrlInfo> jdUrlInfos = asList(jfGoodsReq.getImageInfo().getImageList());
            List<JdUrlInfo> jdUrlInfoList = new ArrayList<>();
            jdUrlInfos.forEach(
                    urlInfo -> {
                        JdUrlInfo jdUrlInfo = new JdUrlInfo();
                        BeanUtils.copyProperties(urlInfo, jdUrlInfo);
                        jdUrlInfoList.add(jdUrlInfo);
                    }
            );
            imageList imageList = new imageList();
            imageList.setUrlInfos(jdUrlInfoList);
            imageList.setWhiteImage(jfGoodsReq.getImageInfo().getWhiteImage());
            jdQueryListResponse.setImageInfo(imageList);
            //金额
            if (jfGoodsReq.getPriceInfo() != null) {
                JdPriceInfo jdPriceInfo = new JdPriceInfo();
                if (jfGoodsReq.getPriceInfo().getHistoryPriceDay() != null)
                    jdPriceInfo.setHistoryPriceDay(jfGoodsReq.getPriceInfo().getHistoryPriceDay());
                if (jfGoodsReq.getPriceInfo().getLowestCouponPrice() != null)
                    jdPriceInfo.setLowestCouponPrice(jfGoodsReq.getPriceInfo().getLowestCouponPrice());
                if (jfGoodsReq.getPriceInfo().getLowestPrice() != null)
                    jdPriceInfo.setLowestPrice(jfGoodsReq.getPriceInfo().getLowestPrice());
                if (jfGoodsReq.getPriceInfo().getPrice() != null)
                    jdPriceInfo.setPrice(jfGoodsReq.getPriceInfo().getPrice());
                jdQueryListResponse.setPriceInfo(jdPriceInfo);
            }
            //商品信息
            if (jfGoodsReq.getShopInfo() != null) {
                JdShopInfo jdShopInfo = new JdShopInfo();
                BeanUtils.copyProperties(jfGoodsReq.getShopInfo(), jdShopInfo);
                jdQueryListResponse.setShopInfo(jdShopInfo);
            }
            //拼购信息
            if (jfGoodsReq.getPinGouInfo() != null) {
                JdPinGouInfo jdPinGouInfo = new JdPinGouInfo();
                if (jfGoodsReq.getPinGouInfo().getPingouEndTime() != null)
                    jdPinGouInfo.setPingouEndTime(jfGoodsReq.getPinGouInfo().getPingouEndTime());
                if (jfGoodsReq.getPinGouInfo().getPingouPrice() != null)
                    jdPinGouInfo.setPingouPrice(jfGoodsReq.getPinGouInfo().getPingouPrice());
                if (jfGoodsReq.getPinGouInfo().getPingouStartTime() != null)
                    jdPinGouInfo.setPingouStartTime(jfGoodsReq.getPinGouInfo().getPingouStartTime());
                if (jfGoodsReq.getPinGouInfo().getPingouTmCount() != null)
                    jdPinGouInfo.setPingouTmCount(jfGoodsReq.getPinGouInfo().getPingouTmCount());
                if (jfGoodsReq.getPinGouInfo().getPingouUrl() != null)
                    jdPinGouInfo.setPingouUrl(jfGoodsReq.getPinGouInfo().getPingouUrl());
                jdQueryListResponse.setPinGouInfo(jdPinGouInfo);
            }
            //资源信息
            JdResourceInfo jdResourceInfo = new JdResourceInfo();
            if (jfGoodsReq.getResourceInfo().getEliteId() != null)
                jdResourceInfo.setEliteId(jfGoodsReq.getResourceInfo().getEliteId());
            if (jfGoodsReq.getResourceInfo().getEliteName() != null)
                jdResourceInfo.setEliteName(jfGoodsReq.getResourceInfo().getEliteName());
            jdQueryListResponse.setResourceInfo(jdResourceInfo);
            //秒杀信息
            JdSeckillInfo seckillInfo = new JdSeckillInfo();
            if (jfGoodsReq.getSeckillInfo() != null) {
                if (jfGoodsReq.getSeckillInfo().getSeckillEndTime() != null)
                    seckillInfo.setSeckillEndTime(jfGoodsReq.getSeckillInfo().getSeckillEndTime());
                if (jfGoodsReq.getSeckillInfo().getSeckillOriPrice() != null)
                    seckillInfo.setSeckillOriPrice(jfGoodsReq.getSeckillInfo().getSeckillOriPrice());
                if (jfGoodsReq.getSeckillInfo().getSeckillPrice() != null)
                    seckillInfo.setSeckillPrice(jfGoodsReq.getSeckillInfo().getSeckillPrice());
                if (jfGoodsReq.getSeckillInfo().getSeckillStartTime() != null)
                    seckillInfo.setSeckillStartTime(jfGoodsReq.getSeckillInfo().getSeckillStartTime());
                jdQueryListResponse.setSeckillInfo(seckillInfo);
            }
            //京喜商品类型，1京喜、2京喜工厂直供、3京喜优选（包含3时可在京东APP购买）
            if (jfGoodsReq.getJxFlags() != null) {
                List<Integer> jxflags = asList(jfGoodsReq.getJxFlags());
                jdQueryListResponse.setJxFlags(jxflags);
            }
            //视频信息
            if (jfGoodsReq.getVideoInfo() != null) {
                JdVideo jdVideo = new JdVideo();
                BeanUtils.copyProperties(jfGoodsReq.getVideoInfo(), jdVideo);
                jdQueryListResponse.setVideo(jdVideo);
            }
            //段子信息
            if (jfGoodsReq.getDocumentInfo() != null) {
                JdDocumentInfo jdDocumentInfo = new JdDocumentInfo();
                BeanUtils.copyProperties(jfGoodsReq.getDocumentInfo(), jdDocumentInfo);
                jdQueryListResponse.setDocumentInfo(jdDocumentInfo);
            }
            //图书信息
            if (jfGoodsReq.getBookInfo() != null) {
                JdBookInfo jdBookInfo = new JdBookInfo();
                BeanUtils.copyProperties(jfGoodsReq.getBookInfo(), jdBookInfo);
                jdQueryListResponse.setBookInfo(jdBookInfo);
            }
            //商品标签
            if (jfGoodsReq.getSkuLabelInfo() != null) {
                JdSkuLabelInfo jdSkuLabelInfo = new JdSkuLabelInfo();
                BeanUtils.copyProperties(jfGoodsReq.getSkuLabelInfo(), jdSkuLabelInfo);
                jdQueryListResponse.setSkuLabelInfo(jdSkuLabelInfo);
            }
            //商品促销标签集
            if (jfGoodsReq.getPromotionLabelInfoList() != null) {
                List<PromotionLabelInfo> promotionLabelInfos = Arrays.asList(jfGoodsReq.getPromotionLabelInfoList());
                List<JdPromotionLabelInfo> jdPromotionLabelInfoLists = new ArrayList<>();
                promotionLabelInfos.forEach(
                        promotionLabelInfo -> {
                            JdPromotionLabelInfo jdPromotionLabelInfoList = new JdPromotionLabelInfo();
                            BeanUtils.copyProperties(promotionLabelInfo, jdPromotionLabelInfoList);
                            jdPromotionLabelInfoLists.add(jdPromotionLabelInfoList);
                        }
                );
                jdQueryListResponse.setPromotionLabelInfoList(jdPromotionLabelInfoLists);
            }
            jdQueryListResponses.add(jdQueryListResponse);
        }
        tableDataInfo.setRows(jdQueryListResponses);
        tableDataInfo.setTotal(response.getQueryResult().getTotalCount());
        return tableDataInfo;
    }

    @Override
    public ResponseResult<JdBigFieldGoodsResponse> details(JdGoodsDetailsRequest request) throws Exception {
        ResponseResult<JdBigFieldGoodsResponse> responseResponseResult = new ResponseResult<>();
        JdClient client = new DefaultJdClient("https://api.jd.com/routerjson", "", "c02c79ce1d4aee0500f6c4c7766700fc", "7d361f4207934d438fe775a854c30e3a");
        UnionOpenGoodsBigfieldQueryRequest unionOpenGoodsBigfieldQueryRequest = new UnionOpenGoodsBigfieldQueryRequest();
        BigFieldGoodsReq goodsReq = new BigFieldGoodsReq();
        Long[] skuId = new Long[]{request.getSkuIds()};
        goodsReq.setSkuIds(skuId);
        unionOpenGoodsBigfieldQueryRequest.setGoodsReq(goodsReq);
        UnionOpenGoodsBigfieldQueryResponse response = client.execute(unionOpenGoodsBigfieldQueryRequest);
        BigFieldGoodsResp[] bigFieldGoodsRespList = response.getQueryResult().getData();
        JdBigFieldGoodsResponse jdBigFieldGoodsResponse = new JdBigFieldGoodsResponse();
        for (BigFieldGoodsResp bigFieldGoodsResp : bigFieldGoodsRespList) {
            BeanUtils.copyProperties(bigFieldGoodsResp, jdBigFieldGoodsResponse);
            //类目信息
            if (bigFieldGoodsResp.getCategoryInfo() != null) {
                JdCategoryInfo jdCategoryInfo = new JdCategoryInfo();
                BeanUtils.copyProperties(bigFieldGoodsResp.getCategoryInfo(), jdCategoryInfo);
                jdBigFieldGoodsResponse.setCategoryInfo(jdCategoryInfo);
            }
            //图片信息
            if (bigFieldGoodsResp.getImageInfo() != null) {
                List<JdUrlInfo> jdUrlInfos = new ArrayList<>();
                List<UrlInfo> urlInfos = Arrays.asList(bigFieldGoodsResp.getImageInfo().getImageList());
                urlInfos.forEach(
                        urlInfo -> {
                            JdUrlInfo jdUrlInfo = new JdUrlInfo();
                            BeanUtils.copyProperties(urlInfo, jdUrlInfo);
                            jdUrlInfos.add(jdUrlInfo);
                        }
                );
                jdBigFieldGoodsResponse.setImageInfo(jdUrlInfos);
            }
            //基础大字段信息
            if (bigFieldGoodsResp.getBaseBigFieldInfo() != null) {
                JdBaseBigFieldInfo jdBaseBigFieldInfo = new JdBaseBigFieldInfo();
                BeanUtils.copyProperties(bigFieldGoodsResp.getBaseBigFieldInfo(), jdBaseBigFieldInfo);
                jdBigFieldGoodsResponse.setBaseBigFieldInfo(jdBaseBigFieldInfo);
            }
            //图书大字段信息
            if (bigFieldGoodsResp.getBookBigFieldInfo() != null) {
                JdBookBigFieldInfo jdBaseBigFieldInfo = new JdBookBigFieldInfo();
                BeanUtils.copyProperties(bigFieldGoodsResp.getBookBigFieldInfo(), jdBaseBigFieldInfo);
                jdBigFieldGoodsResponse.setBookBigFieldInfo(jdBaseBigFieldInfo);
            }
            //影音大字段信息
            if (bigFieldGoodsResp.getVideoBigFieldInfo() != null) {
                JdVideoBigFieldInfo jdVideoBigFieldInfo = new JdVideoBigFieldInfo();
                BeanUtils.copyProperties(bigFieldGoodsResp.getVideoBigFieldInfo(), jdVideoBigFieldInfo);
                jdBigFieldGoodsResponse.setVideoBigFieldInfo(jdVideoBigFieldInfo);
            }
        }
        responseResponseResult.setData(jdBigFieldGoodsResponse);
        return responseResponseResult;
    }

    @Override
    public TableDataInfo<JdQueryListResponse> keyWord(JdKeywordQueryRequest request) throws Exception {
        TableDataInfo<JdQueryListResponse> tableDataInfo = new TableDataInfo<>();
        JdClient client = new DefaultJdClient("https://api.jd.com/routerjson", "", "c02c79ce1d4aee0500f6c4c7766700fc", "7d361f4207934d438fe775a854c30e3a");
        UnionOpenGoodsQueryRequest unionOpenGoodsQueryRequest = new UnionOpenGoodsQueryRequest();
        GoodsReq goodsReqDTO = new GoodsReq();
        BeanUtils.copyProperties(request, goodsReqDTO);
        unionOpenGoodsQueryRequest.setGoodsReqDTO(goodsReqDTO);
        UnionOpenGoodsQueryResponse response = client.execute(unionOpenGoodsQueryRequest);
        if (response.getQueryResult().getData() == null) {
            return tableDataInfo;
        }
        List<GoodsResp> jfGoodsReqs = new ArrayList<>(asList(response.getQueryResult().getData()));
        List<JdQueryListResponse> jdQueryListResponses = new ArrayList<>();
        for (GoodsResp jfGoodsReq : jfGoodsReqs) {
            JdQueryListResponse jdQueryListResponse = new JdQueryListResponse();
            BeanUtils.copyProperties(jfGoodsReq, jdQueryListResponse);
            //类目信息
            JdCategoryInfo jdCategoryInfo = new JdCategoryInfo();
            BeanUtils.copyProperties(jfGoodsReq.getCategoryInfo(), jdCategoryInfo);
            jdQueryListResponse.setCategoryInfo(jdCategoryInfo);
            //佣金信息
            JdCommissionInfo jdCommissionInfo = new JdCommissionInfo();
            BeanUtils.copyProperties(jfGoodsReq.getCommissionInfo(), jdCommissionInfo);
            jdQueryListResponse.setCommissionInfo(jdCommissionInfo);
            //优惠卷信息
            List<JdCoupon> jdCoupons = new ArrayList<>();
            BeanUtils.copyProperties(jfGoodsReq.getCouponInfo().getCouponList(), jdCoupons);
            List<Coupon> coupons = asList(jfGoodsReq.getCouponInfo().getCouponList());
            coupons.forEach(
                    coupon -> {
                        JdCoupon jdCoupon = new JdCoupon();
                        BeanUtils.copyProperties(coupon, jdCoupon);
                        jdCoupons.add(jdCoupon);
                    }
            );
            jdQueryListResponse.setCouponInfo(jdCoupons);
            //图片合集
            List<UrlInfo> jdUrlInfos = asList(jfGoodsReq.getImageInfo().getImageList());
            List<JdUrlInfo> jdUrlInfoList = new ArrayList<>();
            jdUrlInfos.forEach(
                    urlInfo -> {
                        JdUrlInfo jdUrlInfo = new JdUrlInfo();
                        BeanUtils.copyProperties(urlInfo, jdUrlInfo);
                        jdUrlInfoList.add(jdUrlInfo);
                    }
            );
            imageList imageList = new imageList();
            imageList.setUrlInfos(jdUrlInfoList);
            imageList.setWhiteImage(jfGoodsReq.getImageInfo().getWhiteImage());
            jdQueryListResponse.setImageInfo(imageList);
            //金额
            if (jfGoodsReq.getPriceInfo() != null) {
                JdPriceInfo jdPriceInfo = new JdPriceInfo();
                if (jfGoodsReq.getPriceInfo().getHistoryPriceDay() != null)
                    jdPriceInfo.setHistoryPriceDay(jfGoodsReq.getPriceInfo().getHistoryPriceDay());
                if (jfGoodsReq.getPriceInfo().getLowestCouponPrice() != null)
                    jdPriceInfo.setLowestCouponPrice(jfGoodsReq.getPriceInfo().getLowestCouponPrice());
                if (jfGoodsReq.getPriceInfo().getLowestPrice() != null)
                    jdPriceInfo.setLowestPrice(jfGoodsReq.getPriceInfo().getLowestPrice());
                if (jfGoodsReq.getPriceInfo().getPrice() != null)
                    jdPriceInfo.setPrice(jfGoodsReq.getPriceInfo().getPrice());
                jdQueryListResponse.setPriceInfo(jdPriceInfo);
            }
            //商品信息
            if (jfGoodsReq.getShopInfo() != null) {
                JdShopInfo jdShopInfo = new JdShopInfo();
                BeanUtils.copyProperties(jfGoodsReq.getShopInfo(), jdShopInfo);
                jdQueryListResponse.setShopInfo(jdShopInfo);
            }
            //拼购信息
            if (jfGoodsReq.getPinGouInfo() != null) {
                JdPinGouInfo jdPinGouInfo = new JdPinGouInfo();
                if (jfGoodsReq.getPinGouInfo().getPingouEndTime() != null)
                    jdPinGouInfo.setPingouEndTime(jfGoodsReq.getPinGouInfo().getPingouEndTime());
                if (jfGoodsReq.getPinGouInfo().getPingouPrice() != null)
                    jdPinGouInfo.setPingouPrice(jfGoodsReq.getPinGouInfo().getPingouPrice());
                if (jfGoodsReq.getPinGouInfo().getPingouStartTime() != null)
                    jdPinGouInfo.setPingouStartTime(jfGoodsReq.getPinGouInfo().getPingouStartTime());
                if (jfGoodsReq.getPinGouInfo().getPingouTmCount() != null)
                    jdPinGouInfo.setPingouTmCount(jfGoodsReq.getPinGouInfo().getPingouTmCount());
                if (jfGoodsReq.getPinGouInfo().getPingouUrl() != null)
                    jdPinGouInfo.setPingouUrl(jfGoodsReq.getPinGouInfo().getPingouUrl());
                jdQueryListResponse.setPinGouInfo(jdPinGouInfo);
            }
            //京喜商品类型，1京喜、2京喜工厂直供、3京喜优选（包含3时可在京东APP购买）
            if (jfGoodsReq.getJxFlags() != null) {
                List<Integer> jxflags = asList(jfGoodsReq.getJxFlags());
                jdQueryListResponse.setJxFlags(jxflags);
            }
            //视频信息
            if (jfGoodsReq.getVideoInfo() != null) {
                JdVideo jdVideo = new JdVideo();
                BeanUtils.copyProperties(jfGoodsReq.getVideoInfo(), jdVideo);
                jdQueryListResponse.setVideo(jdVideo);
            }
            //段子信息
            if (jfGoodsReq.getDocumentInfo() != null) {
                JdDocumentInfo jdDocumentInfo = new JdDocumentInfo();
                BeanUtils.copyProperties(jfGoodsReq.getDocumentInfo(), jdDocumentInfo);
                jdQueryListResponse.setDocumentInfo(jdDocumentInfo);
            }
            //图书信息
            if (jfGoodsReq.getBookInfo() != null) {
                JdBookInfo jdBookInfo = new JdBookInfo();
                BeanUtils.copyProperties(jfGoodsReq.getBookInfo(), jdBookInfo);
                jdQueryListResponse.setBookInfo(jdBookInfo);
            }
            //商品标签
            if (jfGoodsReq.getSkuLabelInfo() != null) {
                JdSkuLabelInfo jdSkuLabelInfo = new JdSkuLabelInfo();
                BeanUtils.copyProperties(jfGoodsReq.getSkuLabelInfo(), jdSkuLabelInfo);
                jdQueryListResponse.setSkuLabelInfo(jdSkuLabelInfo);
            }
            //商品促销标签集
            if (jfGoodsReq.getPromotionLabelInfoList() != null) {
                List<PromotionLabelInfo> promotionLabelInfos = Arrays.asList(jfGoodsReq.getPromotionLabelInfoList());
                List<JdPromotionLabelInfo> jdPromotionLabelInfoLists = new ArrayList<>();
                promotionLabelInfos.forEach(
                        promotionLabelInfo -> {
                            JdPromotionLabelInfo jdPromotionLabelInfoList = new JdPromotionLabelInfo();
                            BeanUtils.copyProperties(promotionLabelInfo, jdPromotionLabelInfoList);
                            jdPromotionLabelInfoLists.add(jdPromotionLabelInfoList);
                        }
                );
                jdQueryListResponse.setPromotionLabelInfoList(jdPromotionLabelInfoLists);
            }
            jdQueryListResponses.add(jdQueryListResponse);
        }
        tableDataInfo.setRows(jdQueryListResponses);
        tableDataInfo.setTotal(response.getQueryResult().getTotalCount());
        return tableDataInfo;
    }

    @Override
    public ResponseResult<List<JdCategoryResponse>> category(JdCategoryRequest request) throws Exception {
        ResponseResult<List<JdCategoryResponse>> responseResponseResult = new ResponseResult<>();
        JdClient client = new DefaultJdClient("https://api.jd.com/routerjson", "", "c02c79ce1d4aee0500f6c4c7766700fc", "7d361f4207934d438fe775a854c30e3a");
        UnionOpenCategoryGoodsGetRequest unionOpenCategoryGoodsGetRequest = new UnionOpenCategoryGoodsGetRequest();
        CategoryReq req = new CategoryReq();
        BeanUtils.copyProperties(request, req);
        unionOpenCategoryGoodsGetRequest.setReq(req);
        UnionOpenCategoryGoodsGetResponse response = client.execute(unionOpenCategoryGoodsGetRequest);
        List<CategoryResp> categoryResps = Arrays.asList(response.getGetResult().getData());
        List<JdCategoryResponse> categoryResponses = new ArrayList<>();
        categoryResps.forEach(
                categoryResp -> {
                    JdCategoryResponse jdCategoryResponse = new JdCategoryResponse();
                    BeanUtils.copyProperties(categoryResp, jdCategoryResponse);
                    categoryResponses.add(jdCategoryResponse);
                }
        );
        responseResponseResult.setData(categoryResponses);
        return responseResponseResult;
    }

    @Override
    public ResponseResult<JdPromoteResponse> promote(JdPromoteRequest request) throws Exception {
        ResponseResult<JdPromoteResponse> responseResponseResult = new ResponseResult<>();
        JdClient client = new DefaultJdClient("https://api.jd.com/routerjson", "", "c02c79ce1d4aee0500f6c4c7766700fc", "7d361f4207934d438fe775a854c30e3a");
        UnionOpenPromotionBysubunionidGetRequest unionOpenPromotionBysubunionidGetRequest = new UnionOpenPromotionBysubunionidGetRequest();
        PromotionCodeReq promotionCodeReq = new PromotionCodeReq();
        BeanUtils.copyProperties(request, promotionCodeReq);
        unionOpenPromotionBysubunionidGetRequest.setPromotionCodeReq(promotionCodeReq);
        UnionOpenPromotionBysubunionidGetResponse response = client.execute(unionOpenPromotionBysubunionidGetRequest);
        JdPromoteResponse jdPromoteResponse = new JdPromoteResponse();
        BeanUtils.copyProperties(response.getGetResult().getData(), jdPromoteResponse);
        responseResponseResult.setData(jdPromoteResponse);
        return responseResponseResult;
    }
}
